function closeOtherJDialog() {
  $("div.ui-dialog div.ui-dialog-content").dialog("close");
}



// 登录注册页面的轮换
function nTab(thisObj, Num) {
  if (thisObj.className == "active1")
    return;
  var tabObj = thisObj.parentNode.id;
  var tabList = document.getElementById(tabObj).getElementsByTagName("li");
  for ( var i = 0; i <= tabList.length - 1; i++) {
    if (i == Num) {
      thisObj.className = "active1";
      document.getElementById(tabObj + i).style.display = "block";
      $("div.login_k div.bgmid").css("padding-bottom", "12px");
      if ($(thisObj).prev().length == 0) {
        $(thisObj).next().css("border-left", "1px lightgray solid");
        $(thisObj).css("border-right", "");
      }
      if ($(thisObj).next().length == 0) {
        $(thisObj).prev().css("border-right", "1px lightgray solid");
        $(thisObj).css("border-left", "");
      }
    } else {
      document.getElementById(tabObj + i).style.display = "none";
      tabList[i].className = "";
    }
    if (i == 1) {
      $("#registerFocus").focus();
    } else if (i == 0) {
      $("#loginFocus").focus();
    }
  }
}
function log(info) {
  console.log(info);
}
// 找回密码发送邮件
function sendMail() {
  if (!$.trim($("#accountNum").val())) {
    $("#errorAccount").html("账号或别名不能为空");
    $("#errorVerify").html("");
    return;
  }
  if (!$.trim($("#verifyWay").val())) {
    $("#errorAccount").html("");
    $("#errorVerify").html("验证方式不能为空");
    return;
  }
  if (minusing) {
    alert("每分钟只能发一次");
    return;
  }
  $("#errorVerify").html("");
  $("#errorAccount").html("");
  $.ajax({
    url : "findPwd11.action",
    type : "post",
    data : {
      accountNum : $("#accountNum").val(),
      verifyWay : $("#verifyWay").val()
    },
    dataType : "json",
    success : function(data) {
      var dd = eval("(" + data + ")");
      if (dd.d == "Y") {
        $("#mailBtn").attr("disabled", "disabled");
        $("#mailBtn").attr("class", "ghu_btn4");
        minusSecond(10);
      } else if (dd.d == "1") {
        $("#errorAccount").html(dd.info);
      } else if (dd.d == "2") {
        $("#errorVerify").html(dd.info);
      }
    },
    error : function(data) {
      alert("发送过程出错");
    }
  });
}
// 刷新验证码
function refresh(obj) {
  obj.src = "user/getCaptcha?i=" + Math.random();
}
// 文件上传，删除文件
function removeImg(obj) {
  $(obj).parent().parent().remove();
  $("#addFileBtn").removeAttr("disabled");
}
// 添加文件用于上传
function addOneImg(obj) {
  var filesNum = $("#petForm input[id^=dynamicFile]").length;
  if (filesNum >= 5) {
    $(obj).prop("disabled", true);
    return;
  }
  if (filesNum == 4) {
    $(obj).prop("disabled", true);
  }
  var td1 = $("<td height='60' class='r_name'>动态图像</td>");
  var td2 = $("<td class='r_namer'></td>");
  var fileInput = $("<input type='file' name='fileInput' class='r_form1'>");
  fileInput.prop("id", "dynamicFile" + (filesNum + 1));
  var delBtn = $("<input type='button' value='删除' onclick='removeImg(this);'>");
  td2.append(fileInput).append(delBtn);
  var tr = $("<tr>");
  tr.append(td1).append(td2);
  tr.insertAfter($("#petForm input[id^=dynamicFile]:last").parent().parent());
}
// 用于直达顶部
window.onscroll = function() {
  $(window).scrollTop() > 0 ? $("#returnTop").css("bottom", "200px") : $("#returnTop").css("bottom", "-200px");
};
function toTop() {
  $("html, body").animate({
    scrollTop : 0
  }, 120);
  return false;
}
function isEmptyWithTrim(val) {
  return val.trim().length == 0;
}
function validatePet(formName) {
  if (isEmptyWithTrim($("#petName").val())) {
    alert("名称不能为空!");
    return false;
  }
  var files = $("#" + formName).find("input[id^=fileField]");
  var flag = -1;
  files.each(function(i) {
    var fileName = $(this).val().match(/[^\\^\/^\:^\?^\|^\<^\>^\|]*\..{1,8}$/)[0];
    var arr = fileName.split(".");
    var suffix = arr[arr.length - 1];
    if ("jpg|png|gif|bmp|jpeg".indexOf(suffix) == -1) {
      flag = i;
    }
  });
  if (flag == -1) {
    return true;
  } else {
    alert("图片"+(flag+1)+"格式不正确!");
    return false;
  }
}
function validateSite(formName) {
  if (isEmptyWithTrim($("#websiteURL").val())) {
    alert("网址不能为空!");
    return false;
  }
  if (isEmptyWithTrim($("#murl").val())) {
	    alert("手机端网址不能为空!");
	    return false;
	  }
  if (isEmptyWithTrim($("#shortName").val())) {
    alert("网站简称不能为空！");
    return false;
  }
  if (isEmptyWithTrim($("#perclick").val())) {
	    alert("单次点击费用不能为空！");
	    return false;
	  }
  if (isEmptyWithTrim($("#cost").val())) {
	    alert("投入费用不能为空！");
	    return false;
	  }
  if (isEmptyWithTrim($("#fullName").val())) {
    alert("网站全称不能为空！");
    return false;
  }
  if (checkUrl($("#" + formName).find("#websiteURL").val())) {
      alert("网址格式不正确!");
      return false;
  }
  var files = $("#" + formName).find("input[id^=fileField]");
  var flag = -1;
  files.each(function(i) {
    var fileName = $(this).val().match(/[^\\^\/^\:^\?^\|^\<^\>^\|]*\..{1,8}$/)[0];
    var arr = fileName.split(".");
    var suffix = arr[arr.length - 1];
    if ("jpg|png|gif|bmp|jpeg".indexOf(suffix) == -1) {
      flag = i;
    }
  });
  if (flag == -1) {
    return true;
  } else {
    alert("图片"+(flag+1)+"格式不正确!");
    return false;
  }
}
// 检查网址是否合法
function checkUrl(url) {
  return !/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?/.test(url);
}
// 账户管理页面
function popupToolTip(obj, tooltipId) {
  var toolTip = $("#" + tooltipId);
  if (toolTip.is(":visible")) {
    toolTip.hide();
    return;
  }
  var objTop = $(obj).offset().top;
  var objLeft = $(obj).offset().left;
  toolTip.css({top : objTop + 24, left : objLeft - 11});
  $("#" + tooltipId).show();
}
// 解锁页面
function unlockPopupToolTip(obj, tooltipId) {
  var toolTip = $("#" + tooltipId);
  if (toolTip.is(":visible")) {
    toolTip.hide();
    return;
  }
  var objTop = $(obj).offset().top;
  var objLeft = $(obj).offset().left;
  toolTip.css({top : objTop + 32, left : objLeft - 11});
  $("#" + tooltipId).show();
}
// 从前分割
function commonSplit2(obj) {
  var newValue = "";
  var preValue = obj.value.trim().replace(/\s/g, "");
  var n = 3;
  var fragNum = Math.ceil(preValue.length / n);
  for ( var i = 0; i < fragNum; i++) {
    if (i < fragNum - 1) {
      newValue += preValue.slice(n * i, n * (i + 1)) + " ";
    } else {
      newValue += preValue.slice(n * i, n * (i + 1));
    }
  }
  return newValue;
}
// 从后分割
function commonSplit(obj, n) {
  var newValue = "";
  var preValue = obj.value.trim().replace(/\s/g, "");
  var fragNum = Math.ceil(preValue.length / n);
  var arr = new Array();
  for ( var i = fragNum; i > 0; i--) {
    var str = "";
    if (i == 1) {
      str = preValue.slice(0, preValue.length - (fragNum - i) * n);
    } else {
      str = preValue.slice(preValue.length - (fragNum - i + 1) * n, preValue.length - n * (fragNum - i));
    }
    arr.push(str);
  }
  arr.reverse();
  newValue = arr.join(" ");
  return newValue;
}
function addSpace(obj, n) {
  if (/[a-zA-Z]+/g.test(obj.value)) return;
  if (obj.value.length < n)
    return;
  obj.value = commonSplit(obj, n);
}
// 用于分割登陆框的用户名
/*function addChar(obj, e, n) {
  if (/[a-zA-Z]+/g.test(obj.value)) return;
  if (e.keyCode >= 37 && e.keyCode <= 40) return;
  var keys = (e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 60 && e.keyCode <= 90) || e.keyCode == 189;
  var ctrls = e.keyCode == 8 || e.keyCode == 46;
  if (keys || ctrls) {
    if (obj.value.length < n)
      return;
    var preSpaceNum = obj.value.replace(/[^ ]/g, "").length;
    var newValue = commonSplit(obj, n);
    var newSpaceNum = newValue.replace(/[^ ]/g, "").length;
    var s = obj.selectionStart;
    if (keys) {
        s = obj.selectionStart;
        if (newSpaceNum > preSpaceNum) {
          s += 1;
        }
        obj.value = newValue;
    }
    obj.value = newValue;
    obj.setSelectionRange(s, s);
  } else {
    obj.value = obj.value.replace(/[^0-9a-zA-Z_]+/g, "");
    addSpace(obj, n);
  }
}*/
// 用于分割解锁码
function unlockAddChar(obj, e, n) {
  if (e.keyCode >= 37 && e.keyCode <= 40) return;
  var keys = (e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 60 && e.keyCode <= 90) || e.keyCode == 189;
  var ctrls = e.keyCode == 8 || e.keyCode == 46;
  if (keys || ctrls) {
    if (obj.value.length < n)
      return;
    var preSpaceNum = obj.value.replace(/[^ ]/g, "").length;
    var newValue = commonSplit(obj, n);
    var newSpaceNum = newValue.replace(/[^ ]/g, "").length;
    var s = obj.selectionStart;
    if (keys) {
      s = obj.selectionStart;
      if (newSpaceNum > preSpaceNum) {
        s += 1;
      }
      obj.value = newValue;
    }
    obj.value = newValue;
    obj.setSelectionRange(s, s);
  } else {
    obj.value = obj.value.replace(/[^0-9a-zA-Z_]+/g, "");
    addSpace(obj, n);
  }
}
// 选择县
function selectTown(obj, tabIndex, key, fullAddr) {
  $("#selectArea").attr("flag", "full");
  $("#selectArea div").text(fullAddr + $(obj).text());
  $("#areaName").val(fullAddr + $(obj).text());
  var ulTabLi = $("#area_selector div.content div[class=mt] li[data-index="+tabIndex+"]");
  ulTabLi.next().show();
  ulTabLi.find("a").text($(obj).text());
  ulTabLi.find("a").attr("title", $(obj).text());
  ulTabLi.find("a").removeClass("active");
  ulTabLi.find("a").addClass("active");
  $('#area_selector').removeClass('hover');
}
function getCities(obj, tabIndex, key, fullAddr) {
  // 选择省/选择市，并展示其管辖的项
  fullAddr += $(obj).text() + "-";
  var ulTabLi = $("#area_selector div.content div[class=mt] li[data-index="+tabIndex+"]");
  ulTabLi.next().show();
  ulTabLi.find("a").text($(obj).text());
  ulTabLi.find("a").attr("title", $(obj).text());
  ulTabLi.find("a").removeClass("active");
  ulTabLi.next().find("a").addClass("active");
  var provinceIndex = $(obj).attr("data-value");
  key += "_" + provinceIndex;
  var cities = dsy.Items[key];
  var dataArea = $("#area_selector div.content div[class=mc][data-area="+(tabIndex + 1)+"]");
  var cityList = dataArea.find("ul");
  cityList.html("");
  for (var i = 0; i < cities.length; i++) {
    var itemLi = $("<li></li>");
    var itemA = $("<a title='"+ cities[i] +"'>"+ cities[i] +"</a>");
    itemA.attr("href", "javascript:;");
    itemA.attr("data-value", i);
    itemLi.append(itemA);
    cityList.append(itemLi);
  }
  dataArea.show();
  $("#area_selector div.content div[class=mc][data-area!="+(tabIndex + 1)+"]").hide();
  if (tabIndex + 1 < 2) {
    $(cityList).find("li a").click(function() {
      getCities(this, tabIndex + 1, key, fullAddr);
    });
  } else {
    $(cityList).find("li a").click(function() {
      selectTown(this, tabIndex + 1, key, fullAddr);
    });
  }
}
// 选择地址
function selectAddress(obj) {
  var fullAddr = "";
  if ($(obj).attr("flag") == "empty") {
    $("#area_selector div.content div[class=mt] li[data-index!=0]").hide();
    var provinces = dsy.Items["0"];
    var dataArea = $("#area_selector div.content div[class=mc][data-area=0]");
    var provinceList = dataArea.find("ul");
    provinceList.html("");
    for (var i = 0; i < provinces.length; i++) {
      var itemLi = $("<li></li>");
      var itemA = $("<a title='"+ provinces[i] +"'>"+ provinces[i] +"</a>");
      itemA.attr("href", "javascript:;");
      itemA.attr("data-value", i);
      itemLi.append(itemA);
      provinceList.append(itemLi);
    }
    dataArea.show();
    $(provinceList).find("li a").click(function() {
      getCities(this, 0, "0", fullAddr);
    });
  }
  $('#area_selector').toggleClass('hover');
}
// 手动切换tab
function turnTab(obj) {
  var i = $(obj).parent().attr("data-index");
  $(obj).addClass("active");
  $(obj).parent().siblings().find("a").removeClass("active");
  $("#area_selector div.content div[class=mc][data-area=" + i + "]").show();
  $("#area_selector div.content div[class=mc][data-area!=" + i + "]").hide();
}
function goOutSite(obj, type) {
  $.ajax({
    url : "user/goOutSite.action",
    type : "post",
    async : true,
    data : "id=" + $(obj).next().val() + "&type=" + type
  });
  return true;
}
function changeUserComplain(obj, divId) {
  $(obj).css("background-color", "#49AFDE");
  $(obj).css("color", "#fff");
  $(obj).parent().siblings().find("a").css("background-color", "#EFF5F9");
  $(obj).parent().siblings().find("a").css("color", "#000");
  $("div[class*=fakeClass2]").each(function() {
    if ($(this).is(":visible")) {
      $(this).hide();
    }
  });
  $("#" + divId).show();
}
function turnShop(obj, divId) {
  $(obj).addClass("active");
  $(obj).parent().siblings().find("a").removeClass("active");
  $("#" + divId).parent().find("div.fakeClass").hide();
  $("#" + divId).show();
  
}
// 定制文件上传
function changeType(objFile) {
  var objtype = objFile.substring(objFile.lastIndexOf(".")).toLowerCase();
  var fileType = new Array(".jpeg", ".jpg", ".gif", ".png", ".bmp");
  for (var i = 0; i < fileType.length; i++) {
    if (objtype == fileType[i]) {
      return true;
    }
  }
  return false;
}
function selectPic(fileInput, errId) {
  if (changeType(fileInput.value)) {
    $(fileInput).prev().val(fileInput.value);
    $("#" + errId).html("");
  } else {
    $("#" + errId).html("限定格式为： (.jpeg .jpg .gif .png .bmp).");
  }
}
// 使用ajax校验
function clearErrors(formId) {
  var errorSpans = $("#" + formId).find("span.errorMessage[id]");
  for(var i = 0; i < errorSpans.length; i++) {
    errorSpans[i].innerHTML = "";
  }
}
function showErrors(formId, errors) {
  var errorSpans = $("#" + formId).find("span.errorMessage[id]");
  for(fieldName in errors.fieldErrors) {
    for(var i = 0; i < errorSpans.length; i++) {
      if (fieldName === errorSpans[i].id) {
        errorSpans[i].innerHTML = errors.fieldErrors[fieldName][0];
        break;
      }
    }
  }
}
function validate(formId, action, handleSecondAjax) {
  var flag = false;
  var serialInfo = $('#' + formId).serialize();
   $.ajax({
     url : action,
     type : "post",
     data : encodeURI(serialInfo) + '&struts.enableJSONValidation=true&struts.validateOnly=true',
     dataType : "json",
     async : false,
     success : function(data) {
       clearErrors(formId);
       var errorsObject = StrutsUtils.getValidationErrors(data);
       if(errorsObject.fieldErrors) {
         showErrors(formId, errorsObject);
       } else {
         flag = afterValidate(formId, action, encodeURI(serialInfo), handleSecondAjax);
       }
     }
   });
   return flag;
}
function afterValidate(formId, action, serialInfo, handleSecondAjax) {
  var flag = false;
  var receiveAccount = 0;
   $.ajax({
     url : action,
     type : "post",
     data : serialInfo,
     dataType : "json",
     async : true,
     success : function(data) { 
       clearErrors(formId);
       if (data.length > 0) {
         data = eval("(" + data + ")");
         var errorsObject = StrutsUtils.getValidationErrors(data);
         if(errorsObject.fieldErrors) {
           showErrors(formId, errorsObject);
         } else if (data.type == "transfer") {
           receiveAccount = 1;
           document.location.href = "receiveAccount.action";
         } else if (data.type == "payed") { 
           receiveAccount = 1;
           document.location.href = "user/noLogin_fillAccountInfo_.action";
         } else if (data.type == "ok") {
           receiveAccount = 1;
           document.location.href = "/";
         } else {
           flag = true;
         }
         if (receiveAccount == 0) {
           handleSecondAjax(flag, formId);
         }
       }
     }
   });
   return flag;
}
// 处理返回的json信息
function commonHandleSecondAjax(flag, formId) {
  if (flag) {
    $('#updateSuccess').show();
    $('#updateFail').hide();
  } else {
    $('#updateSuccess').hide();
    $('#updateFail').show();
  }
}
function handleEditPet(flag, formId) {
  if (flag) {
    $("#" + formId).find("span.fontgreen").show();
  } else {
    $("#" + formId).find("span.fontgreen").hide();
  }
}
var i = 5;
function handleUnlockAccount(flag, formId) {
  if (flag) {
    $("#unlockOK").show();
    var inter = setInterval(function() {
      secs.innerHTML = --i;
      if (i == 0) {
        document.location.href = "page_login.action";
        clearInterval(inter);
      }
    }, 1000);
  } else {
    $("#unlockOK").hide();
  }
}
function hideSuccessAndFail() {
  $('#updateSuccess').hide();
  $('#updateFail').hide();
}
// 校验之后的常用信息提示
function commonValidate(formId, action, commonHandleSecondAjax) {
  hideSuccessAndFail();
  validate(formId, action, commonHandleSecondAjax);
}
function checkEqualPass1(obj) {
  var nextPassInput = $(obj).parent().parent().next().find("input[type=password]");
  if (obj.value.length > 5 && nextPassInput.val().length > 5 && obj.value == nextPassInput.val()) {
    nextPassInput.next().show();
  } else {
    nextPassInput.next().hide(); 
  }
}
function checkEqualPass2(obj) {
  var prevPass = $(obj).parent().parent().prev().find("input[type=password]").val();
  if (obj.value.length > 5 && prevPass.length > 5 && obj.value == prevPass) {
    $(obj).next().show();
  } else {
    $(obj).next().hide();
  }
}
// 检查密码强度
function showStrength(obj) {
  var objTop = $(obj).offset().top;
  var objLeft = $(obj).offset().left;
  $("#passStrength").css({top : objTop, left : objLeft + 310});
  $("#passStrength").show();
}
function checkPassStrength(obj) {
  var val = obj.value.replace(/\s/g, "");
  if (val.length < 6) {
    $("#passStrength .strengthImg").prev().html("至少6位");
    $("#passStrength .strengthImg div").css("background-color", "#f1f1f1");
    return;
  }
  var onlyNumReg = /^\d+$/g;
  var onlyCharReg = /^[a-zA-Z]+$/g;
  var onlySpecialReg = /^[\~\!\@\#\$\%\^\&\*\(\)\-_\=\+]+$/g;
  if (onlyNumReg.test(val) || onlyCharReg.test(val) || onlySpecialReg.test(val)) {
    $("#passStrength .strengthImg").prev().html("强度：低");
    $("#passStrength .strengthImg div:eq(0)").css("background-color", "red");
    $("#passStrength .strengthImg div:gt(0)").css("background-color", "#f1f1f1");
    return;
  }
  var numReg = /\d+/g;
  var charReg = /[a-zA-Z]+/g;
  var specialReg = /[\~\!\@\#\$\%\^\&\*\(\)\-_\=\+]+/g;
  if (numReg.test(val) && charReg.test(val) && specialReg.test(val)) {
    $("#passStrength .strengthImg").prev().html("强度：高");
    $("#passStrength .strengthImg div").css("background-color", "#53b520");
  } else if ((numReg.test(val) && charReg.test(val)) || (numReg.test(val) && specialReg.test(val))
      || (specialReg.test(val) && charReg.test(val))) {
    $("#passStrength .strengthImg").prev().html("强度：中");
    $("#passStrength .strengthImg div:lt(2)").css("background-color", "#e9ba54");
    $("#passStrength .strengthImg div:eq(2)").css("background-color", "#f1f1f1");
  }
}
// 发布宠物，验证信息
function validateReleasePet(formId) {
  var flag = 0;
  var petForm = $("#" + formId);
  petForm.find("input[type=file][id$=File]").each(function(i) {
    if ($(this).val().length == 0) {
      flag = 1;
      return;
    }
  });
  if (flag == 1) {
    alert("图像不全");
    return false;
  }
  if (/\D/g.test(petForm.find("input[name=pet\\.price]").val())) {
    log(document.getElementById("pet\.price"));
    document.getElementById("pet\.price").innerHTML = "单价应为整数";
    document.getElementById("pet\.name").innerHTML = "";
    return false;
  }
  $.ajax({
    url : "release/submitPet.action",
    type : "post",
    data : petForm.serialize() + '&struts.enableJSONValidation=true&struts.validateOnly=true',
    dataType : "json",
    async : false,
    success : function(data) {
      clearErrors(formId);
      var errorsObject = StrutsUtils.getValidationErrors(data);
      if(errorsObject.fieldErrors) {
        showErrors(formId, errorsObject);
        flag = 1;
      }
    }
  });
  return flag == 0;
}
// 发布网站logo格式
function changeSiteType(objFile) {
  var objtype = objFile.substring(objFile.lastIndexOf(".")).toLowerCase();
  var fileType = new Array(".png");
  for (var i = 0; i < fileType.length; i++) {
    if (objtype == fileType[i]) {
      return true;
    }
  }
  return false;
}
function selectSitePic(fileInput, errId) {
  if (changeSiteType(fileInput.value)) {
    $(fileInput).prev().val(fileInput.value);
    $("#" + errId).html("");
  } else {
    $("#" + errId).html("限定格式为： (.png).");
  }
}
// 发布宠物动态图片格式
function changePetType(objFile) {
  var objtype = objFile.substring(objFile.lastIndexOf(".")).toLowerCase();
  var fileType = new Array(".gif");
  for (var i = 0; i < fileType.length; i++) {
    if (objtype == fileType[i]) {
      return true;
    }
  }
  return false;
}
function selectPetPic(fileInput, errId) {
  if (changePetType(fileInput.value)) {
    $(fileInput).prev().val(fileInput.value);
    $("#" + errId).html("");
  } else {
    $("#" + errId).html("限定格式为： (.gif).");
  }
}
// 弹出确定发送到手机的tooltip
function popupSendCode(obj, type, tooltipId, phoneNum, newOrNot) {
  var toolTip = $("#" + tooltipId);
  if (toolTip.is(":visible")) {
    toolTip.hide();
    return;
  }
  if (!checkPhoneRegex(phoneNum)) {
    alert("手机格式不对");
    return;
  }
  $("#myPhone").text(phoneNum);
  var objTop = $(obj).offset().top;
  var objLeft = $(obj).offset().left;
  toolTip.css({top : objTop + 34, left : objLeft - 11});
  var confirmBtn = toolTip.find("input[value=确定]");
  confirmBtn.unbind("click");
  confirmBtn.click(function() {
    getRandomCode(obj, type, phoneNum, newOrNot);
    toolTip.hide();
  });
  toolTip.show();
}
// 弹出确定发送到邮箱的tooltip
function popupSendEmailCode(obj, type, tooltipId, email, newOrNot) {
  var toolTip = $("#" + tooltipId);
  if (toolTip.is(":visible")) {
    toolTip.hide();
    return;
  }
  if (!checkEmailRegex(email)) {
    alert("邮箱格式不对");
    return;
  }
  $("#myEmail").text(email);
  var objTop = $(obj).offset().top;
  var objLeft = $(obj).offset().left;
  toolTip.css({top : objTop + 34, left : objLeft - 11});
  var confirmBtn = toolTip.find("input[value=确定]");
  confirmBtn.unbind("click");
  confirmBtn.click(function() {
    getRandomCode(obj, type, email, newOrNot);
    toolTip.hide();
  });
  toolTip.show();
}
// 获取验证码验证码
function getRandomCode(obj, type, phoneOrEmail, newOrNot) {
  var serialStr = "";
  serialStr = "type=" + type + "&phoneOrEmail=" + phoneOrEmail;
  /*if (type == "40") {
    var val = $("#username").val();
    if (val.length == 0) {
      alert("账户不能为空");
      return;
    } else 
    
    {
      serialStr += "&username=" + val;
    }
  }*/
  // 重新发送
  $(obj).attr("disabled", "disabled");
  $(obj).addClass("gray_btn");
  if ($(obj).next().val() && $(obj).next().val().indexOf("邮箱获取") > -1) {
    $(obj).next().attr("disabled", "disabled");
    $(obj).next().addClass("gray_btn");
    $(obj).next().val("重新发送(60秒)");
  }
  minusSecond2(300, newOrNot);
  $.ajax({
    url : "getRandomCode.action",
    type : "post",
    data : serialStr,
    dataType : "json",
    success : function(data) {
      var d = eval("(" + data + ")"); 
      if(d.submitError) {
        clearTimeout(minusTimeout);
        $("#phoneBtn").removeAttr("disabled").removeClass("gray_btn").val(newOrNot + "获取验证码");
        $("#emailBtn").removeAttr("disabled").removeClass("gray_btn").val(newOrNot + "邮箱获取");
        alert(d.submitError);
      } else {
        // 重新发送
//        $(obj).attr("disabled", "disabled");
//        $(obj).addClass("gray_btn");
// $(obj).val("重新发送(60秒)");
//        if ($(obj).next().val() && $(obj).next().val().indexOf("邮箱获取") > -1) {
//          $(obj).next().attr("disabled", "disabled");
//          $(obj).next().addClass("gray_btn");
//          $(obj).next().val("重新发送(60秒)");
//        }
//        minusSecond2(300, newOrNot);
      }
    }
  });
}
var minusing = false;
var minusTimeout = null;
function updateSendBtn(i, newOrNot) {
  var phoneBtn = $("#phoneBtn");
  var emailBtn = $("#emailBtn");
  var phoneBtn1 = $("#emailBtn1");
  var emailBtn1 = $("#phoneBtn1");
  if(newOrNot=="新"){
	  phoneBtn1.attr("disabled", "disabled").addClass("gray_btn").val("重新发送(" + i + "秒)");
	  emailBtn1.attr("disabled", "disabled").addClass("gray_btn").val("重新发送(" + i + "秒)");

  }
  else{
  phoneBtn.attr("disabled", "disabled").addClass("gray_btn").val("重新发送(" + i + "秒)");
  emailBtn.attr("disabled", "disabled").addClass("gray_btn").val("重新发送(" + i + "秒)");
  }
  if (i == 0) {
    clearTimeout(minusTimeout);
    if(newOrNot=="新"){
        phoneBtn1.removeAttr("disabled").removeClass("gray_btn").val(newOrNot + "获取验证码");
        emailBtn1.removeAttr("disabled").removeClass("gray_btn").val(newOrNot + "邮箱验证码");

    }else{
    phoneBtn.removeAttr("disabled").removeClass("gray_btn").val(newOrNot + "获取验证码");
    emailBtn.removeAttr("disabled").removeClass("gray_btn").val(newOrNot + "邮箱获取");
    }
  }
}
// 递减数秒
function minusSecond2(s, newOrNot) {
  minusTimeout = window.setTimeout("minusSecond2(" + (s - 1) + "," + "'" + newOrNot +  "'" + ")", 1000);
  updateSendBtn(s, newOrNot);
}
function checkPhoneRegex(phoneNum) {
  return /^1\d{10}$/g.test(phoneNum);
}
function checkEmailRegex(email) {
  return /^\s*\w+(?:\.{0,1}[\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\.[a-zA-Z]+\s*$/g.test(email);
}
function checkPageInput(obj, totalPage) {
  if (obj.value > totalPage) {
    obj.value = totalPage;
  }
}
/*(function ($) {
    $.fn.placeholder = function (options) {
        var defaults = {
            pColor: "#ccc",
            pActive: "#999",
            pFont: "14px",
            activeBorder: "#080",
            posL: 8,
            zIndex: "99"
        },
        opts = $.extend(defaults, options);
        //
        return this.each(function () {
            if ("placeholder" in document.createElement("input")) return;
            $(this).parent().css("position", "relative");
            var isIE = $.browser.msie,
            version = $.browser.version;
  
            //不支持placeholder的浏览器
            var $this = $(this),
                msg = $this.attr("placeholder"),
                iH = $this.outerHeight(),
                iW = $this.outerWidth(),
                iX = $this.position().left,
                iY = $this.position().top,
                oInput = $("<label>", {
                "class": "test",
                "text": msg,
                "css": {
                    "position": "absolute",
                    "left": iX + "px",
                    "top": iY + "px",
                    "width": iW - opts.posL + "px",
                    "padding-left": opts.posL + "px",
                    "height": iH + "px",
                    "line-height": iH + "px",
                    "color": opts.pColor,
                    "font-size": opts.pFont,
                    "z-index": opts.zIndex,
                    "cursor": "text"
                }
                }).insertBefore($this);
            //初始状态就有内容
            var value = $this.val();
            if (value.length > 0) {
            oInput.hide();
            };
  
            //
            $this.on("focus", function () {
                var value = $(this).val();
                if (value.length > 0) {
                    oInput.hide();
                }
                oInput.css("color", opts.pActive);
                //
  
                if(isIE && version < 9){
                    var myEvent = "propertychange";
                }else{
                    var myEvent = "input";
                }
  
                $(this).on(myEvent, function () {
                    var value = $(this).val();
                    if (value.length == 0) {
                        oInput.show();
                    } else {
                        oInput.hide();
                    }
                });
  
            }).on("blur", function () {
                var value = $(this).val();
                if (value.length == 0) {
                    oInput.css("color", opts.pColor).show();
                }
            });
            //
            oInput.on("click", function () {
                $this.trigger("focus");
                $(this).css("color", opts.pActive)
            });
            //
            $this.filter(":focus").trigger("focus");
        });
    }
})(jQuery)
*/
/*
 * jQuery placeholder, fix for IE6,7,8,9
 * @author JENA
 * @since 20131115.1504
 * @website ishere.cn
 */
var JPlaceHolder = {
    //检测
    _check : function(){
        return 'placeholder' in document.createElement('input');
    },
    //初始化
    init : function(){
        if(!this._check()){
            this.fix();
        }
    },
    //修复
    fix : function(){
        jQuery(':input[placeholder]').each(function(index, element) {
            var self = $(this), txt = self.attr('placeholder');
            self.wrap($('<div></div>').css({position:'relative', zoom:'1', border:'none', background:'none', padding:'none', margin:'none'}));
            var pos = self.position(), h = self.outerHeight(true), paddingleft = self.css('padding-left');
            var holder = $('<span></span>').text(txt).css({position:'absolute', left:pos.left, top:pos.top+'10px', height:h, lienHeight:h, paddingLeft:paddingleft, color:'#aaa'}).appendTo(self.parent());
            self.focusin(function(e) {
                holder.hide();
            }).focusout(function(e) {
                if(!self.val()){
                    holder.show();
                }
            });
            holder.click(function(e) {
                holder.hide();
                self.focus();
            });
        });
    }
};
//执行
jQuery(function(){
    JPlaceHolder.init();    
});